/**
 * 新增页面JS
 */
$(function(){
    //激活左侧导航菜单
    activeNavBar("MANAGE_USER_INFO");
    initSelect2();
    $('#file').ace_file_input({
        style:'well',
        btn_choose:'点击选择图片',
        btn_change:null,
        no_icon:'ace-icon fa fa-picture-o',
        thumbnail:'large',
        droppable:true,
        maxSize: 1024 * 1024 * 3,
        before_change:function(files, dropped){
            return isImageFile(files);
        }
    });

    $("#saveBtn").click(function(){
        save();
    });
    $("#goBackBtn, #headGoBackBtn").click(function(){
        window.forward(springUrl+ "/web/userInfo/index");
    });
});

/**
 * 保存
 */
function save(){
    if($('#addForm').trigger("validate").isValid()){
        var index =  layer.msg('正在处理中...', {icon: 16, shade: 0.3, time: 0});
        var formData = new FormData();
        formData.append("file", $("#file")[0].files[0]);
        formData.append("userAccount", $("#userAccount").val());
        formData.append("userPassword", $("#userPassword").val());
        formData.append("userName", $("#userName").val());
        formData.append("userPhone", $("#userPhone").val());
        jQuery.ajax({
            type: "POST",
            url: springUrl+"/web/userInfo/insert",
            data: formData,
            async: false,
            processData : false,
            contentType : false,
            success:function (data) {
                layer.close(index);
                Alert.success("数据保存成功!", function(){
                    window.forward(springUrl+ "/web/userInfo/index");
                });
            },
            error : function(data){
                layer.close(index);
                Alert.error(data.responseText);
            }
        });
    }
}

